//
//  LZQ_SecondVC.swift
//  SwiftExercise
//
//  Created by 罗宗庆 on 2021/6/24.
//

import UIKit
import HandyJSON



class LZQ_SecondVC: BaseViewController{
    
    
    var dataSource:[String]?
    
    @IBOutlet weak var tableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.initViewTableView()
    }
    
    
    func initViewTableView(){
        self.tableView.dataSource = self
        self.tableView.delegate = self
        self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        self.tableView.separatorStyle = .none
        self.tableView.emptyView = EmptyView{ [weak self] in
            self?.dataSource = ["我","是","你","爹"]
            self?.tableView.reloadData()
        }
        self.tableView.mj_header = LZQ_MJRefreshHeader{ [weak self] in
            self?.loadData()
            
        }
        self.tableView.mj_header?.beginRefreshing()
    }
    func loadData(){
        
        var params = [String:String]()
        params["branches"] = "1253"
        params["passwd"] = "123123"
        
        LZQ_NetworkTool.manager.loadData(url: "https://api.aixunmiao.com/api/v1/customer/login", para: params, isShowLoading: true) { response in
            if response != nil {
                if response?.code == 0{

                    //返回model 
//                    HomeModel.deserialize(from: response?.message)
                    
                    //返回数组对象
//                    if let jsonObject = HomeModel.deserialize(from: response?.data!["list"].debugDescription) {
//
//                    }
                    
                    
                    
                }else{
                    Toast.showToast(msg: "请求错误")
                }
            }
            self.tableView.mj_header?.endRefreshing()
        }
    }
}




extension LZQ_SecondVC:UITableViewDataSource,UITableViewDelegate{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource?.count ?? 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell")!
        cell.textLabel?.text = self.dataSource?[indexPath.row]
        cell.selectionStyle = .none
        return cell
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 69
    }
}
